package com.lemon.smartsafetynew.net.services;

import android.content.Context;

import com.lemon.android.http.LemonRequestParams;
import com.lemon.smartsafety.app.Constants;
import com.lemon.smartsafety.app.IApplication;
import com.lemon.smartsafety.app.RefreshType;
import com.lemon.smartsafety.http.UrlInfo;
import com.lemon.smartsafety.http.callback.HandlerCallback;
import com.lemon.smartsafety.http.service.BaseHttpServices;
import com.lemon.smartsafetynew.entity.device.DeviceOverviewVo;
import com.lemon.smartsafetynew.entity.device.DeviceVo;
import com.lemon.smartsafetynew.entity.incident.IncidentVo;
import com.lemon.smartsafetynew.util.constants.KeyConstants;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;

/**
 * 设备管理 网络请求接口汇总
 * Created by Andrew on 2017/9/25.
 */

public class DeviceServices extends BaseHttpServices {

    public static final String TAG = "DeviceServices";

    private DeviceServices(Context context) {
        super(context);
    }

    /**
     * 初始化，等同使用构造函数
     *
     * @return
     */
    public static DeviceServices init() {
        return new DeviceServices(IApplication.context());
    }


    /**
     * 初始化，等同使用构造函数
     *
     * @param context
     * @return
     */
    public static DeviceServices init(Context context) {
        return new DeviceServices(context);
    }

    /**
     * 获取设备列表
     *
     * @param type
     * @param params
     */
    public void getDeviceList(RefreshType type, LemonRequestParams params) {

        HandlerCallback<List<DeviceVo>> callback = new HandlerCallback<List<DeviceVo>>(KeyConstants.URL_GET_DEVICE_LIST) {
        };
        callback.setOther(type);
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_DEVICE_LIST, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }

    /**
     * 获取设备管理概览
     *
     * @param params
     */
    public void getDeviceManger(LemonRequestParams params) {

        HandlerCallback<List<DeviceOverviewVo>> callback = new HandlerCallback<List<DeviceOverviewVo>>(KeyConstants.URL_GET_DEVICE_MANAGER) {
        };
        String serverUrl = mSharedPreferencesServer.getRequestUrl(UrlInfo.GET_DEVICE_MANAGER, Constants.SERVER_V2);
        OkHttpUtils.post()
                .url(serverUrl)
                .tag(callback.getTag())
                .params(params)
                .build().execute(callback);
    }
}
